package pro.lingwu.station.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pro.lingwu.station.dto.db.Passenger;
import pro.lingwu.station.service.PassengerService;

/**
 *
 * @author @lingwu
 * @date created in 2021/11/16
 */
@Api(tags = "passenger")
@RestController
public class PassengerController {

    private final PassengerService service;

    public PassengerController(PassengerService service) {
        this.service = service;
    }

    @ApiOperation(value = "添加乘客")
    @PostMapping("/passenger")
    public ResponseEntity<?> addPassenger(Passenger passenger){
        service.addPassenger(passenger);
        return ResponseEntity.ok("添加成功");
    }

    @ApiOperation(value = "获取账号下的所有乘客")
    @GetMapping("/passenger")
    public ResponseEntity<?> getPassengers(String account){
        return ResponseEntity.ok(service.findPassengerByAccount(account));
    }

    @ApiOperation(value = "更新用户账号下的某个乘客信息")
    @PutMapping("/passenger/{id}")
    public ResponseEntity<?> updatePassenger(String account,
                                             @PathVariable int id){
        return ResponseEntity.ok("");
    }

    @ApiOperation(value = "删除用户账号下的某个乘客信息")
    @DeleteMapping("/passenger/{id}")
    public ResponseEntity<?> deletePassenger(@PathVariable Long id){
        service.rmPassenger(id);
        return ResponseEntity.ok("");
    }

}
